﻿using System.Collections.Generic;
using Pap.Data;
using Pap.Data.Abstraction.Utils;
using Pap.Web.Utils;

namespace Pap.Web.Modules.Administration.ViewModel
{
    /// <summary>
    /// 
    /// </summary>
    public class ProjectsListViewModel : IViewModel
    {
        /// <summary>
        /// 
        /// </summary>
        IAdministrationRepository _Repo;

        /// <summary>
        /// Initializes a new instance of the <see cref="ProjectsListViewModel"/> class.
        /// </summary>
        /// <param name="repository">The repository.</param>
        public ProjectsListViewModel(IAdministrationRepository repository)
        {
            _Repo = repository;
        }

        /// <summary>
        /// Gets all projects.
        /// </summary>
        /// <returns></returns>
        public IEnumerable<IProject> GetAllProjects()
        {
            return _Repo.FindProjects(project => true);
        }

        /// <summary>
        /// Deletes the last project.
        /// </summary>
        public void DeleteLastProject()
        {
            using (IUnitOfWork transaction = this.GetInstance<IUnitOfWork>())
            {
                IProject project = _Repo.GetLastStage().ProjectObj;
                _Repo.DeleteProject(project);
                transaction.Commit();
            }
        }
    }
}
